IT[X]
[ class tree: IT[X] ] [ index: IT[X] ] [ all elements ]

Source for file ITX.php

Documentation is available at ITX.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | Copyright (c) 1997-2005 Ulf Wendel, Pierre-Alain Joye                |
  5. // +----------------------------------------------------------------------+
  6. // | This source file is subject to the New BSD license, That is bundled  |
  7. // | with this package in the file LICENSE, and is available through      |
  8. // | the world-wide-web at                                                |
  9. // | http://www.opensource.org/licenses/bsd-license.php                   |
  10. // | If you did not receive a copy of the new BSD license and are unable  |
  11. // | to obtain it through the world-wide-web, please send a note to       |
  12. // | pajoye@php.net so we can mail you a copy immediately.                |
  13. // +----------------------------------------------------------------------+
  14. // | Author: Ulf Wendel <ulf.wendel@phpdoc.de>                            |
  15. // |         Pierre-Alain Joye <pajoye@php.net>                           |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: ITX.php,v 1.15 2006/04/12 00:50:44 pajoye Exp $
  19. //
  20.  
  21. require_once 'HTML/Template/IT.php';
  22. require_once 'HTML/Template/IT_Error.php';
  23.  
  24. /**
  25. * Integrated Template Extension - ITX
  26. *
  27. * With this class you get the full power of the phplib template class.
  28. * You may have one file with blocks in it but you have as well one main file
  29. * and multiple files one for each block. This is quite usefull when you have
  30. * user configurable websites. Using blocks not in the main template allows
  31. * you to modify some parts of your layout easily.
  32. *
  33. * Note that you can replace an existing block and add new blocks at runtime.
  34. * Adding new blocks means changing a variable placeholder to a block.
  35. *
  36. @author   Ulf Wendel <uw@netuse.de>
  37. @access   public
  38. @version  $Id: ITX.php,v 1.15 2006/04/12 00:50:44 pajoye Exp $
  39. @package  IT[X]
  40. */
  41. {
  42.     /**
  43.     * Array with all warnings.
  44.     * @var    array 
  45.     * @access public
  46.     * @see    $printWarning, $haltOnWarning, warning()
  47.     */
  48.     var $warn = array();
  49.  
  50.     /**
  51.     * Print warnings?
  52.     * @var    array 
  53.     * @access public
  54.     * @see    $haltOnWarning, $warn, warning()
  55.     */
  56.     var $printWarning = false;
  57.  
  58.     /**
  59.     * Call die() on warning?
  60.     * @var    boolean 
  61.     * @access public
  62.     * @see    $warn, $printWarning, warning()
  63.     */
  64.     var $haltOnWarning = false;
  65.  
  66.     /**
  67.     * RegExp used to test for a valid blockname.
  68.     * @var string 
  69.     */
  70.     var $checkblocknameRegExp = '';
  71.  
  72.     /**
  73.     * Functionnameprefix used when searching function calls in the template.
  74.     * @var string 
  75.     */
  76.     var $functionPrefix = 'func_';
  77.  
  78.     /**
  79.     * Functionname RegExp.
  80.     * @var string 
  81.     */
  82.     var $functionnameRegExp = '[_a-zA-Z]+[A-Za-z_0-9]*';
  83.  
  84.     /**
  85.     * RegExp used to grep function calls in the template.
  86.     *
  87.     * The variable gets set by the constructor.
  88.     *
  89.     * @var string 
  90.     * @see HTML_Template_IT()
  91.     */
  92.     var $functionRegExp = '';
  93.  
  94.     /**
  95.     * List of functions found in the template.
  96.     *
  97.     * @var array 
  98.     */
  99.     var $functions = array();
  100.  
  101.     /**
  102.     * List of callback functions specified by the user.
  103.     *
  104.     * @var array 
  105.     */
  106.     var $callback = array();
  107.  
  108.     /**
  109.     * Builds some complex regexps and calls the constructor
  110.     * of the parent class.
  111.     *
  112.     * Make sure that you call this constructor if you derive your own
  113.     * template class from this one.
  114.     *
  115.     * @see    HTML_Template_IT()
  116.     */
  117.     function HTML_Template_ITX($root '')
  118.     {
  119.  
  120.         $this->checkblocknameRegExp = '@' $this->blocknameRegExp . '@';
  121.         $this->functionRegExp = '@' $this->functionPrefix . '(' .
  122.                                 $this->functionnameRegExp . ')\s*\(@sm';
  123.  
  124.         $this->HTML_Template_IT($root);
  125.     // end func constructor
  126.  
  127.     function init()
  128.     {
  129.         $this->free();
  130.         $this->buildFunctionlist();
  131.         $this->findBlocks($this->template);
  132.         // we don't need it any more
  133.         $this->template = '';
  134.         $this->buildBlockvariablelist();
  135.  
  136.     // end func init
  137.  
  138.     /**
  139.     * Replaces an existing block with new content.
  140.     *
  141.     * This function will replace a block of the template and all blocks
  142.     * contained in the replaced block and add a new block insted, means
  143.     * you can dynamically change your template.
  144.     *
  145.     * Note that changing the template structure violates one of the IT[X]
  146.     * development goals. I've tried to write a simple to use template engine
  147.     * supporting blocks. In contrast to other systems IT[X] analyses the way
  148.     * you've nested blocks and knows which block belongs into another block.
  149.     * The nesting information helps to make the API short and simple. Replacing
  150.     * blocks does not only mean that IT[X] has to update the nesting
  151.     * information (relatively time consumpting task) but you have to make sure
  152.     * that you do not get confused due to the template change itself.
  153.     *
  154.     * @param    string      Blockname
  155.     * @param    string      Blockcontent
  156.     * @param    boolean     true if the new block inherits the content
  157.     *                        of the old block
  158.     * @return   boolean 
  159.     * @throws   IT_Error
  160.     * @see      replaceBlockfile(), addBlock(), addBlockfile()
  161.     * @access   public
  162.     */
  163.     function replaceBlock($block$template$keep_content = false)
  164.     {
  165.         if (!isset($this->blocklist[$block])) {
  166.             return new IT_Error(
  167.             "The block "."'$block'".
  168.             " does not exist in the template and thus it can't be replaced.",
  169.             __FILE____LINE__
  170.             );
  171.         }
  172.  
  173.         if ($template == ''{
  174.             return new IT_Error('No block content given.'__FILE____LINE__);
  175.         }
  176.  
  177.         if ($keep_content{
  178.             $blockdata $this->blockdata[$block];
  179.         }
  180.  
  181.         // remove all kinds of links to the block / data of the block
  182.         $this->removeBlockData($block);
  183.  
  184.         $template = "<!-- BEGIN $block -->" . $template . "<!-- END $block -->";
  185.         $parents $this->blockparents[$block];
  186.         $this->findBlocks($template);
  187.         $this->blockparents[$block$parents;
  188.  
  189.         // KLUDGE: rebuild the list for all block - could be done faster
  190.         $this->buildBlockvariablelist();
  191.  
  192.         if ($keep_content{
  193.             $this->blockdata[$block$blockdata;
  194.         }
  195.  
  196.         // old TODO - I'm not sure if we need this
  197.         // update caches
  198.  
  199.         return true;
  200.     // end func replaceBlock
  201.  
  202.     /**
  203.     * Replaces an existing block with new content from a file.
  204.     *
  205.     * @brother replaceBlock()
  206.     * @param    string    Blockname
  207.     * @param    string    Name of the file that contains the blockcontent
  208.     * @param    boolean   true if the new block inherits the content of the old block
  209.     */
  210.     function replaceBlockfile($block$filename$keep_content = false)
  211.     {
  212.         return $this->replaceBlock($block$this->getFile($filename)$keep_content);
  213.     // end func replaceBlockfile
  214.  
  215.     /**
  216.     * Adds a block to the template changing a variable placeholder
  217.     * to a block placeholder.
  218.     *
  219.     * Add means "replace a variable placeholder by a new block".
  220.     * This is different to PHPLibs templates. The function loads a
  221.     * block, creates a handle for it and assigns it to a certain
  222.     * variable placeholder. To to the same with PHPLibs templates you would
  223.     * call set_file() to create the handle and parse() to assign the
  224.     * parsed block to a variable. By this PHPLibs templates assume
  225.     * that you tend to assign a block to more than one one placeholder.
  226.     * To assign a parsed block to more than only the placeholder you specify
  227.     * in this function you have to use a combination of getBlock()
  228.     * and setVariable().
  229.     *
  230.     * As no updates to cached data is necessary addBlock() and addBlockfile()
  231.     * are rather "cheap" meaning quick operations.
  232.     *
  233.     * The block content must not start with <!-- BEGIN blockname -->
  234.     * and end with <!-- END blockname --> this would cause overhead and
  235.     * produce an error.
  236.     *
  237.     * @param    string    Name of the variable placeholder, the name must be unique
  238.     *                      within the template.
  239.     * @param    string    Name of the block to be added
  240.     * @param    string    Content of the block
  241.     * @return   boolean 
  242.     * @throws   IT_Error
  243.     * @see      addBlockfile()
  244.     * @access   public
  245.     */
  246.     function addBlock($placeholder$blockname$template)
  247.     {
  248.         // Don't trust any user even if it's a programmer or yourself...
  249.         if ($placeholder == ''{
  250.             return new IT_Error('No variable placeholder given.',
  251.                                 __FILE____LINE__
  252.                                 );
  253.         elseif ($blockname == '' ||
  254.                     !preg_match($this->checkblocknameRegExp$blockname)
  255.         {
  256.             return new IT_Error("No or invalid blockname '$blockname' given.",
  257.                     __FILE____LINE__
  258.                     );
  259.         elseif ($template == ''{
  260.             return new IT_Error('No block content given.'__FILE____LINE__);
  261.         elseif (isset($this->blocklist[$blockname])) {
  262.             return new IT_Error('The block already exists.',
  263.                                 __FILE____LINE__
  264.                             );
  265.         }
  266.  
  267.         // find out where to insert the new block
  268.         $parents $this->findPlaceholderBlocks($placeholder);
  269.         if (count($parents== 0{
  270.  
  271.             return new IT_Error(
  272.                 "The variable placeholder".
  273.                 " '$placeholder' was not found in the template.",
  274.                 __FILE____LINE__
  275.             );
  276.  
  277.         elseif (count($parents> 1{
  278.  
  279.             reset($parents);
  280.             while (list($k$parenteach($parents)) {
  281.                 $msg .= "$parent";
  282.             }
  283.             $msg substr($parent-2);
  284.  
  285.             return new IT_Error("The variable placeholder "."'$placeholder'".
  286.                                 " must be unique, found in multiple blocks '$msg'.",
  287.                                 __FILE____LINE__
  288.                                 );
  289.         }
  290.  
  291.         $template = "<!-- BEGIN $blockname -->" . $template . "<!-- END $blockname -->";
  292.         $this->findBlocks($template);
  293.         if ($this->flagBlocktrouble{
  294.             return false;    // findBlocks() already throws an exception
  295.         }
  296.         $this->blockinner[$parents[0]][$blockname;
  297.         $this->blocklist[$parents[0]] preg_replace(
  298.                     '@' $this->openingDelimiter . $placeholder .
  299.                     $this->closingDelimiter . '@',
  300.  
  301.                     $this->openingDelimiter . '__' $blockname '__' .
  302.                     $this->closingDelimiter,
  303.  
  304.                     $this->blocklist[$parents[0]]
  305.                 );
  306.  
  307.         $this->deleteFromBlockvariablelist($parents[0]$placeholder);
  308.         $this->updateBlockvariablelist($blockname);
  309.     /*
  310.     // check if any inner blocks were found
  311.     if(is_array($this->blockinner[$blockname]) and count($this->blockinner[$blockname]) > 0) {
  312.         // loop through inner blocks, registering the variable placeholders in each
  313.         foreach($this->blockinner[$blockname] as $childBlock) {
  314.             $this->updateBlockvariablelist($childBlock);
  315.         }
  316.     }
  317.     */
  318.         return true;
  319.     // end func addBlock
  320.  
  321.     /**
  322.     * Adds a block taken from a file to the template changing a variable
  323.     * placeholder to a block placeholder.
  324.     *
  325.     * @param      string    Name of the variable placeholder to be converted
  326.     * @param      string    Name of the block to be added
  327.     * @param      string    File that contains the block
  328.     * @brother    addBlock()
  329.     */
  330.     function addBlockfile($placeholder$blockname$filename)
  331.     {
  332.         return $this->addBlock($placeholder$blockname$this->getFile($filename));
  333.     // end func addBlockfile
  334.  
  335.     /**
  336.     * Returns the name of the (first) block that contains
  337.     * the specified placeholder.
  338.     *
  339.     * @param    string  Name of the placeholder you're searching
  340.     * @param    string  Name of the block to scan. If left out (default)
  341.     *                    all blocks are scanned.
  342.     * @return   string  Name of the (first) block that contains
  343.     *                    the specified placeholder.
  344.     *                    If the placeholder was not found or an error occured
  345.     *                    an empty string is returned.
  346.     * @throws   IT_Error
  347.     * @access   public
  348.     */
  349.     function placeholderExists($placeholder$block '')
  350.     {
  351.         if ($placeholder == ''{
  352.             new IT_Error('No placeholder name given.'__FILE____LINE__);
  353.             return '';
  354.         }
  355.  
  356.         if ($block != '' && !isset($this->blocklist[$block])) {
  357.             new IT_Error("Unknown block '$block'."__FILE____LINE__);
  358.             return '';
  359.         }
  360.  
  361.         // name of the block where the given placeholder was found
  362.         $found '';
  363.  
  364.         if ($block != ''{
  365.             if (is_array($variables $this->blockvariables[$block])) {
  366.                 // search the value in the list of blockvariables
  367.                 reset($variables);
  368.                 while (list($k$variableeach($variables)) {
  369.                     if ($k == $placeholder{
  370.                         $found $block;
  371.                         break;
  372.                     }
  373.                 }
  374.             }
  375.         else {
  376.  
  377.             // search all blocks and return the name of the first block that
  378.             // contains the placeholder
  379.             reset($this->blockvariables);
  380.             while (list($blockname$variableseach($this->blockvariables)){
  381.                 if (is_array($variables&& isset($variables[$placeholder])) {
  382.                     $found $blockname;
  383.                     break;
  384.                 }
  385.             }
  386.         }
  387.  
  388.         return $found;
  389.     // end func placeholderExists
  390.  
  391.     /**
  392.     * Checks the list of function calls in the template and
  393.     * calls their callback function.
  394.     *
  395.     * @access    public
  396.     */
  397.     function performCallback()
  398.     {
  399.         reset($this->functions);
  400.         while (list($func_id$functioneach($this->functions)) {
  401.             if (isset($this->callback[$function['name']])) {
  402.                 if ($this->callback[$function['name']]['object'!= ''{
  403.                     $this->variableCache['__function' $func_id '__'=
  404.                         call_user_func(
  405.                         array(
  406.                         &$GLOBALS[$this->callback[$function['name']]['object']],
  407.                         $this->callback[$function['name']]['function']),
  408.                         $function['args']
  409.                        );
  410.                 else {
  411.                     $this->variableCache['__function' $func_id '__'=
  412.                             call_user_func(
  413.                             $this->callback[$function['name']]['function'],
  414.                             $function['args']
  415.                         );
  416.                 }
  417.             }
  418.         }
  419.  
  420.     // end func performCallback
  421.  
  422.     /**
  423.     * Returns a list of all function calls in the current template.
  424.     *
  425.     * @return   array 
  426.     * @access   public
  427.     */
  428.     function getFunctioncalls()
  429.     {
  430.         return $this->functions;
  431.     // end func getFunctioncalls
  432.  
  433.     /**
  434.     * Replaces a function call with the given replacement.
  435.     *
  436.     * @param    int       Function ID
  437.     * @param    string    Replacement
  438.     * @deprec
  439.     */
  440.     function setFunctioncontent($functionID$replacement)
  441.     {
  442.         $this->variableCache['__function' $functionID '__'$replacement;
  443.     // end func setFunctioncontent
  444.  
  445.     /**
  446.     * Sets a callback function.
  447.     *
  448.     * IT[X] templates (note the X) can contain simple function calls.
  449.     * "function call" means that the editor of the template can add
  450.     * special placeholder to the template like 'func_h1("embedded in h1")'.
  451.     * IT[X] will grab this function calls and allow you to define a callback
  452.     * function for them.
  453.     *
  454.     * This is an absolutely evil feature. If your application makes heavy
  455.     * use of such callbacks and you're even implementing if-then etc. on
  456.     * the level of a template engine you're reiventing the wheel... - that's
  457.     * actually how PHP came into life. Anyway, sometimes it's handy.
  458.     *
  459.     * Consider also using XML/XSLT or native PHP. And please do not push
  460.     * IT[X] any further into this direction of adding logics to the template
  461.     * engine.
  462.     *
  463.     * For those of you ready for the X in IT[X]:
  464.     *
  465.     * <?php
  466.     * ...
  467.     * function h_one($args) {
  468.     *    return sprintf('<h1>%s</h1>', $args[0]);
  469.     * }
  470.     *
  471.     * ...
  472.     * $itx = new HTML_Template_ITX( ... );
  473.     * ...
  474.     * $itx->setCallbackFunction('h1', 'h_one');
  475.     * $itx->performCallback();
  476.     * ?>
  477.     *
  478.     * template:
  479.     * func_h1('H1 Headline');
  480.     *
  481.     * @param    string    Function name in the template
  482.     * @param    string    Name of the callback function
  483.     * @param    string    Name of the callback object
  484.     * @return   boolean   False on failure.
  485.     * @throws   IT_Error
  486.     * @access   public
  487.     */
  488.     function
  489.     setCallbackFunction($tplfunction$callbackfunction$callbackobject '')
  490.     {
  491.         if ($tplfunction == '' || $callbackfunction == ''{
  492.             return new IT_Error(
  493.                 "No template function "."('$tplfunction')".
  494.                 " and/or no callback function ('$callback') given.",
  495.                     __FILE____LINE__
  496.                 );
  497.         }
  498.         $this->callback[$tplfunction= array(
  499.                                           'function' => $callbackfunction,
  500.                                           'object'   => $callbackobject
  501.                                         );
  502.  
  503.         return true;
  504.     // end func setCallbackFunction
  505.  
  506.     /**
  507.     * Sets the Callback function lookup table
  508.     *
  509.     * @param    array    function table
  510.     *                     array[templatefunction] =
  511.     *                        array(
  512.     *                                "function" => userfunction,
  513.     *                                "object" => userobject
  514.     *                        )
  515.     * @access    public
  516.     */
  517.     function setCallbackFuntiontable($functions)
  518.     {
  519.         $this->callback = $functions;
  520.     // end func setCallbackFunctiontable
  521.  
  522.     /**
  523.     * Recursively removes all data assiciated with a block, including all inner blocks
  524.     *
  525.     * @param    string  block to be removed
  526.     */
  527.     function removeBlockData($block)
  528.     {
  529.         if (isset($this->blockinner[$block])) {
  530.             foreach ($this->blockinner[$blockas $k => $inner{
  531.                 $this->removeBlockData($inner);
  532.             }
  533.  
  534.             unset($this->blockinner[$block]);
  535.         }
  536.  
  537.         unset($this->blocklist[$block]);
  538.         unset($this->blockdata[$block]);
  539.         unset($this->blockvariables[$block]);
  540.         unset($this->touchedBlocks[$block]);
  541.  
  542.     // end func removeBlockinner
  543.  
  544.     /**
  545.     * Returns a list of blocknames in the template.
  546.     *
  547.     * @return    array    [blockname => blockname]
  548.     * @access    public
  549.     * @see        blockExists()
  550.     */
  551.     function getBlocklist()
  552.     {
  553.         $blocklist = array();
  554.         foreach ($this->blocklist as $block => $content{
  555.             $blocklist[$block$block;
  556.         }
  557.  
  558.         return $blocklist;
  559.     // end func getBlocklist
  560.  
  561.     /**
  562.     * Checks wheter a block exists.
  563.     *
  564.     * @param    string 
  565.     * @return    boolean 
  566.     * @access    public
  567.     * @see        getBlocklist()
  568.     */
  569.     function blockExists($blockname)
  570.     {
  571.         return isset($this->blocklist[$blockname]);
  572.     // end func blockExists
  573.  
  574.     /**
  575.     * Returns a list of variables of a block.
  576.     *
  577.     * @param    string    Blockname
  578.     * @return    array    [varname => varname]
  579.     * @access    public
  580.     * @see        BlockvariableExists()
  581.     */
  582.     function getBlockvariables($block)
  583.     {
  584.         if (!isset($this->blockvariables[$block])) {
  585.             return array();
  586.         }
  587.  
  588.         $variables = array();
  589.         foreach ($this->blockvariables[$blockas $variable => $v{
  590.             $variables[$variable$variable;
  591.         }
  592.  
  593.         return $variables;
  594.     // end func getBlockvariables
  595.  
  596.     /**
  597.     * Checks wheter a block variable exists.
  598.     *
  599.     * @param    string    Blockname
  600.     * @param    string    Variablename
  601.     * @return    boolean 
  602.     * @access    public
  603.     * @see    getBlockvariables()
  604.     */
  605.     function BlockvariableExists($block$variable)
  606.     {
  607.         return isset($this->blockvariables[$block][$variable]);
  608.     // end func BlockvariableExists
  609.  
  610.     /**
  611.     * Builds a functionlist from the template.
  612.     */
  613.     function buildFunctionlist()
  614.     {
  615.         $this->functions = array();
  616.  
  617.         $template $this->template;
  618.         $num = 0;
  619.  
  620.         while (preg_match($this->functionRegExp$template$regs)) {
  621.  
  622.             $pos strpos($template$regs[0]);
  623.             $template substr($template$pos strlen($regs[0]));
  624.  
  625.             $head $this->getValue($template')');
  626.             $args = array();
  627.  
  628.             $search $regs[0$head ')';
  629.  
  630.             $replace $this->openingDelimiter .
  631.                        '__function' $num '__' .
  632.                        $this->closingDelimiter;
  633.  
  634.             $this->template = str_replace($search$replace$this->template);
  635.             $template       str_replace($search$replace$template);
  636.  
  637.             while ($head != '' && $args2 $this->getValue($head',')) {
  638.                 $arg2 trim($args2);
  639.                 $args[('"' == $arg2{0|| "'" == $arg2{0}?
  640.                                     substr($arg21-1$arg2;
  641.                 if ($arg2 == $head{
  642.                     break;
  643.                 }
  644.                 $head substr($headstrlen($arg2+ 1);
  645.             }
  646.  
  647.             $this->functions[$num++= array(
  648.                                                 'name'    => $regs[1],
  649.                                                 'args'    => $args
  650.                                             );
  651.         }
  652.  
  653.     // end func buildFunctionlist
  654.  
  655.     function getValue($code$delimiter{
  656.         if ($code == ''{
  657.             return '';
  658.         }
  659.  
  660.         if (!is_array($delimiter)) {
  661.             $delimiter = array$delimiter => true );
  662.         }
  663.  
  664.         $len         strlen($code);
  665.         $enclosed    = false;
  666.         $enclosed_by '';
  667.  
  668.         if (isset($delimiter[$code[0]])) {
  669.             $i = 1;
  670.         else {
  671.             for ($i = 0; $i $len; ++$i{
  672.                 $char $code[$i];
  673.  
  674.                 if (
  675.                         ($char == '"' || $char == "'"&&
  676.                         ($char == $enclosed_by || '' == $enclosed_by&&
  677.                         (0 == $i || ($i > 0 && '\\' != $code[$i - 1]))
  678.                     {
  679.  
  680.                     if (!$enclosed{
  681.                         $enclosed_by $char;
  682.                     else {
  683.                         $enclosed_by "";
  684.                     }
  685.                     $enclosed !$enclosed;
  686.  
  687.                 }
  688.  
  689.                 if (!$enclosed && isset($delimiter[$char])) {
  690.                     break;
  691.                 }
  692.             }
  693.         }
  694.  
  695.         return substr($code0$i);
  696.     // end func getValue
  697.  
  698.     /**
  699.     * Deletes one or many variables from the block variable list.
  700.     *
  701.     * @param    string    Blockname
  702.     * @param    mixed     Name of one variable or array of variables
  703.     *                      ( array ( name => true ) ) to be stripped.
  704.     */
  705.     function deleteFromBlockvariablelist($block$variables)
  706.     {
  707.         if (!is_array($variables)) {
  708.             $variables = array($variables => true);
  709.         }
  710.  
  711.         reset($this->blockvariables[$block]);
  712.         while (list($varname$valeach($this->blockvariables[$block])) {
  713.             if (isset($variables[$varname])) {
  714.                 unset($this->blockvariables[$block][$varname]);
  715.             }
  716.         }
  717.     // end deleteFromBlockvariablelist
  718.  
  719.     /**
  720.     * Updates the variable list of a block.
  721.     *
  722.     * @param    string    Blockname
  723.     */
  724.     function updateBlockvariablelist($block)
  725.     {
  726.         preg_match_all$this->variablesRegExp,
  727.                         $this->blocklist[$block]$regs
  728.                     );
  729.  
  730.         if (count($regs[1]!= 0{
  731.             foreach ($regs[1as $k => $var{
  732.                 $this->blockvariables[$block][$var= true;
  733.             }
  734.         else {
  735.             $this->blockvariables[$block= array();
  736.         }
  737.  
  738.         // check if any inner blocks were found
  739.         if (isset($this->blockinner[$block]&&
  740.             is_array($this->blockinner[$block]&&
  741.             count($this->blockinner[$block]> 0
  742.         {
  743.             /*
  744.              * loop through inner blocks, registering the variable
  745.              * placeholders in each
  746.              */
  747.             foreach ($this->blockinner[$blockas $childBlock{
  748.                 $this->updateBlockvariablelist($childBlock);
  749.             }
  750.         }
  751.     // end func updateBlockvariablelist
  752.  
  753.     /**
  754.     * Returns an array of blocknames where the given variable
  755.     * placeholder is used.
  756.     *
  757.     * @param    string    Variable placeholder
  758.     * @return    array    $parents    parents[0..n] = blockname
  759.     */
  760.     function findPlaceholderBlocks($variable)
  761.     {
  762.         $parents = array();
  763.         reset($this->blocklist);
  764.         while (list($blockname$contenteach($this->blocklist)) {
  765.             reset($this->blockvariables[$blockname]);
  766.             while (
  767.                 list($varname$valeach($this->blockvariables[$blockname]))
  768.             {
  769.                 if ($variable == $varname{
  770.                     $parents[$blockname;
  771.                 }
  772.             }
  773.         }
  774.  
  775.         return $parents;
  776.     // end func findPlaceholderBlocks
  777.  
  778.     /**
  779.     * Handles warnings, saves them to $warn and prints them or
  780.     * calls die() depending on the flags
  781.     *
  782.     * @param    string    Warning
  783.     * @param    string    File where the warning occured
  784.     * @param    int       Linenumber where the warning occured
  785.     * @see      $warn, $printWarning, $haltOnWarning
  786.     */
  787.     function warning($message$file ''$line = 0)
  788.     {
  789.         $message sprintf(
  790.                     'HTML_Template_ITX Warning: %s [File: %s, Line: %d]',
  791.                     $message,
  792.                     $file,
  793.                     $line
  794.                 );
  795.  
  796.         $this->warn[$message;
  797.  
  798.         if ($this->printWarning{
  799.             print $message;
  800.         }
  801.  
  802.         if ($this->haltOnWarning{
  803.             die($message);
  804.         }
  805.     // end func warning
  806.  
  807. // end class HTML_Template_ITX
  808. ?>

Documentation generated on Mon, 11 Mar 2019 14:38:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.